﻿Option Explicit On
Public Class BlockOneAppraisals

    Dim QuestionNumber As Integer
    Dim dtmTest As Date
    Dim dtmTest2 As Date

    'Declare the Array as 10 rows and 3 columns
    Dim ArrayMax As Integer = 51 'One number past the end of actual info in array
    Dim HWQuestions(ArrayMax, 3) As String
    Dim intQuestionCount As Integer = 1
    Dim intChoiceACount As Integer = 2
    Dim intChoiceBCount As Integer = 3
    Dim intChoiceCCount As Integer = 4
    Dim intChoiceDCount As Integer = 5
    Dim intFirstRun As Integer = 1
    Dim QC As Integer
    Dim intRightAnswer As String = 0
    Dim intWrongAnswer As String = 0
    Dim Form As Object
    Dim strUser As String = "Enter Last Name"


    Shared Property MidiParent As MainForm

    Private Sub CloseToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles CloseToolStripMenuItem.Click
        Me.Close()
    End Sub

    Private Sub BlockOneHomework_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        '************************************************
        '****** Questions Are Loaded Here****************
        '******* Column 1 is Questions and Choices*******
        '******* Column 2 is Correct/Not Correct*********
        '******* Column 3 is Reference ******************
        HWQuestions(1, 1) = "1. How many years must a regular Airman be in service before they are promoted to Senior Airman?"
        HWQuestions(2, 1) = "Choice 1A"
        HWQuestions(2, 2) = "Correct"
        HWQuestions(2, 3) = "Student Workbook page 18"
        HWQuestions(3, 1) = "Choice 1B"
        HWQuestions(3, 2) = "Not Correct"
        HWQuestions(4, 1) = "Choice 1C"
        HWQuestions(4, 2) = "Not Correct"
        HWQuestions(5, 1) = "Choice 1D"
        HWQuestions(5, 2) = "Not Correct"
        HWQuestions(6, 1) = "2. Stepped to next question"
        HWQuestions(7, 1) = "Choice 2A"
        HWQuestions(7, 2) = "Not Correct"
        HWQuestions(8, 1) = "Choice 2B"
        HWQuestions(8, 2) = "Correct"
        HWQuestions(8, 3) = "????????????????????????"
        HWQuestions(9, 1) = "Choice 2C"
        HWQuestions(9, 2) = "Not Correct"
        HWQuestions(10, 1) = "Choice 2D"
        HWQuestions(10, 2) = "Not Correct"
        HWQuestions(11, 1) = "3. Stepped again."
        HWQuestions(12, 1) = "Choice 3A"
        HWQuestions(13, 1) = "Choice 3B"
        HWQuestions(14, 1) = "Choice 3C"
        HWQuestions(14, 2) = "Correct"
        HWQuestions(15, 1) = "Choice 3D"
        HWQuestions(16, 1) = "4. Worked as planned"
        HWQuestions(17, 1) = "Choice 4A"
        HWQuestions(18, 1) = "Choice 4B"
        HWQuestions(19, 1) = "Choice 4C"
        HWQuestions(20, 1) = "Choice 4D"
        HWQuestions(20, 2) = "Correct"
        HWQuestions(21, 1) = "5. Stepped to next question"
        HWQuestions(22, 1) = "Choice 5A"
        HWQuestions(23, 1) = "Choice 5B"
        HWQuestions(24, 1) = "Choice 5C"
        HWQuestions(25, 1) = "Choice 5D"
        HWQuestions(26, 1) = "6. Stepped again."
        HWQuestions(27, 1) = "Choice 6A"
        HWQuestions(28, 1) = "Choice 6B"
        HWQuestions(29, 1) = "Choice 6C"
        HWQuestions(30, 1) = "Choice 6D"
        HWQuestions(31, 1) = "7. Worked as planned"
        HWQuestions(32, 1) = "Choice 7A"
        HWQuestions(33, 1) = "Choice 7B"
        HWQuestions(34, 1) = "Choice 7C"
        HWQuestions(35, 1) = "Choice 7D"
        HWQuestions(36, 1) = "8. Stepped to next question"
        HWQuestions(37, 1) = "Choice 8A"
        HWQuestions(38, 1) = "Choice 8B"
        HWQuestions(39, 1) = "Choice 8C"
        HWQuestions(40, 1) = "Choice 8D"
        HWQuestions(41, 1) = "9. Stepped again."
        HWQuestions(42, 1) = "Choice 9A"
        HWQuestions(43, 1) = "Choice 9B"
        HWQuestions(44, 1) = "Choice 9C"
        HWQuestions(45, 1) = "Choice 9D"
        HWQuestions(46, 1) = "10. Stepped to next question"
        HWQuestions(47, 1) = "Choice 10A"
        HWQuestions(48, 1) = "Choice 10B"
        HWQuestions(49, 1) = "Choice 10C"
        HWQuestions(50, 1) = "Choice 10D"
        HWQuestions(51, 1) = "Close"
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        If Button1.Text = "START" Then

        End If
        If Button1.Text = "Start" Then
            Button1.Text = "New Question"
        ElseIf Button1.Text = "Done" Then
            Results()
        End If
        Clear_Display()
        If intFirstRun = 1 Then
            strUser = InputBox("Please enter last name", strUser)
            txtQuestion.Text = HWQuestions(1, 1)
            txtChoiceA.Text = HWQuestions(2, 1)
            txtChoiceB.Text = HWQuestions(3, 1)
            txtChoiceC.Text = HWQuestions(4, 1)
            txtChoiceD.Text = HWQuestions(5, 1)
            intFirstRun = 2
            WriteToFile()
        ElseIf intFirstRun = 2 And intQuestionCount < 46 Then
            Next_Question(HWQuestions)
        End If

        CheckAnswer()

        dtmTest = TimeValue(Now)
        dtmTest2 = DateValue(Now)
        junk.Text = dtmTest
        junk2.Text = dtmTest2

        Return
    End Sub

    Private Sub Clear_Display()
        txtQuestion.Clear()
        txtChoiceA.Clear()
        txtChoiceA.BackColor = Color.WhiteSmoke
        txtChoiceB.Clear()
        txtChoiceB.BackColor = Color.WhiteSmoke
        txtChoiceC.Clear()
        txtChoiceC.BackColor = Color.WhiteSmoke
        txtChoiceD.Clear()
        txtChoiceD.BackColor = Color.WhiteSmoke
        txtReference.Clear()
    End Sub

    Public Function Next_Question(HWQuestions As String(,))
        intQuestionCount = intQuestionCount + 5
        txtQuestion.Text = HWQuestions(intQuestionCount, 1)
        intChoiceACount = intChoiceACount + 5
        txtChoiceA.Text = HWQuestions(intChoiceACount, 1)
        intChoiceBCount = intChoiceBCount + 5
        txtChoiceB.Text = HWQuestions(intChoiceBCount, 1)
        intChoiceCCount = intChoiceCCount + 5
        txtChoiceC.Text = HWQuestions(intChoiceCCount, 1)
        intChoiceDCount = intChoiceDCount + 5
        txtChoiceD.Text = HWQuestions(intChoiceDCount, 1)
        If intQuestionCount = 46 Then
            Button1.Text = "Done"
        End If
        Return intQuestionCount
    End Function

    Private Function CheckFirstRun(ByVal intFirstRun As Integer) As Integer
        If intFirstRun = 1 Then
            txtQuestion.Text = HWQuestions(1, 1)
            txtChoiceA.Text = HWQuestions(2, 1)
            txtChoiceB.Text = HWQuestions(3, 1)
            txtChoiceC.Text = HWQuestions(4, 1)
            txtChoiceD.Text = HWQuestions(5, 1)
            WriteToFile()
        End If
        intFirstRun = 2
        Return intFirstRun
    End Function

    Private Sub txtChoiceA_Click(sender As System.Object, e As System.EventArgs) Handles txtChoiceA.Click
        If HWQuestions(intChoiceACount, 2) = "Correct" Then
            txtChoiceA.BackColor = Color.ForestGreen
        ElseIf HWQuestions(intChoiceACount, 2) = "Not Correct" Then
            txtChoiceA.BackColor = Color.Red
        End If
        If txtChoiceA.BackColor = Color.ForestGreen Then
            txtReference.Text = HWQuestions(intChoiceACount, 3)
        End If
        'CheckAnswer()
    End Sub

    Private Sub txtChoiceB_Click(sender As System.Object, e As System.EventArgs) Handles txtChoiceB.Click
        If HWQuestions(intChoiceBCount, 2) = "Correct" Then
            txtChoiceB.BackColor = Color.ForestGreen
        ElseIf HWQuestions(intChoiceBCount, 2) = "Not Correct" Then
            txtChoiceB.BackColor = Color.Red
        End If
        'CheckAnswer()
    End Sub

    Private Sub txtChoiceC_Click(sender As System.Object, e As System.EventArgs) Handles txtChoiceC.Click
        If HWQuestions(intChoiceCCount, 2) = "Correct" Then
            txtChoiceC.BackColor = Color.ForestGreen
        ElseIf HWQuestions(intChoiceCCount, 2) = "Not Correct" Then
            txtChoiceC.BackColor = Color.Red
        End If
        'CheckAnswer()
    End Sub

    Private Sub txtChoiceD_Click(sender As System.Object, e As System.EventArgs) Handles txtChoiceD.Click
        If HWQuestions(intChoiceDCount, 2) = "Correct" Then
            txtChoiceD.BackColor = Color.ForestGreen
        ElseIf HWQuestions(intChoiceDCount, 2) = "Not Correct" Then
            txtChoiceD.BackColor = Color.Red
        End If
        'CheckAnswer()
    End Sub

    Private Sub Results()
        MsgBox("Right Answer: " + intRightAnswer & vbNewLine & _
               "Wrong Answer: " + intWrongAnswer, vbOKOnly, "Results")
    End Sub

    Private Sub CheckAnswer()
        Dim textboxs = New Collection
        textboxs.Add(HWQuestions(intChoiceACount, 2))
        textboxs.Add(HWQuestions(intChoiceBCount, 2))
        textboxs.Add(HWQuestions(intChoiceCCount, 2))
        textboxs.Add(HWQuestions(intChoiceDCount, 2))

        For Each Box In textboxs
            If Box = "Not Correct" Then
                intWrongAnswer = intWrongAnswer + 1

            ElseIf Box = "Correct" Then
                intRightAnswer = intRightAnswer + 1

            End If
        Next
    End Sub
    Private Sub WriteToFile()
        Dim FILE_NAME As String = "C:\Users\DJWalshy\Desktop\test2.txt"

        If System.IO.File.Exists(FILE_NAME) = True Then
            Dim objWriter As New System.IO.StreamWriter(FILE_NAME, True)
            objWriter.WriteLine(strUser)
            objWriter.WriteLine((DateValue(Now)) & "   " & (TimeValue(Now)))
            objWriter.WriteLine(txtQuestion.Text)
            objWriter.WriteLine(txtChoiceA.Text)
            objWriter.WriteLine(txtChoiceB.Text)
            objWriter.WriteLine(txtChoiceC.Text)
            objWriter.WriteLine(txtChoiceD.Text)
            objWriter.WriteLine()
            objWriter.Close()
            'MsgBox("Text written to file")
        Else
            MsgBox("File Does Not Exist")
        End If
    End Sub

End Class